package com.fyzk.activity.chongzhi;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.tyjc.lottery.R;
import com.fyzk.view.myview.MyWebView;

public class CZ_ZhiFuBao_Web extends Activity{
	private ImageView top_back;

	private MyWebView webView;

	private String url;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.cz_zhifubao_web);

		url = getIntent().getStringExtra("url");

		info();
	}

	@SuppressLint("JavascriptInterface")
	private void info(){
		top_back = (ImageView)findViewById(R.id.zfb_web_iv_back);

		webView = (MyWebView)findViewById(R.id.zfb_web);

		webView.getSettings().setJavaScriptEnabled(true);
//		webView.setDownloadListener(new DownloadListener() {
//			
//			@Override
//			public void onDownloadStart(String url, String userAgent,
//					String contentDisposition, String mimetype, long contentLength) {
//				Log.e("zhengzai...", "jiazai");
//				if (url != null && url.startsWith("http://"))
//                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
//			}
//		});
		webView.setInitialScale(80);

//		webView.getSettings().setUseWideViewPort(true); 
//		webView.getSettings().setLoadWithOverviewMode(true); 
		// 添加js调用接口
		if(Build.VERSION.SDK_INT>=17){
			webView.addJavascriptInterface(this, "android");
		}



		webView.setWebViewClient(new WebViewClient(){
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				Log.e("web  url", "url: "+url);
				view.loadUrl(url);
				return true;
			}
		});

		webView.loadUrl(url);



		top_back.setOnClickListener(new ZFB_web_OnClick());
	}


	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
                   return true;
        }

		return super.onKeyDown(keyCode, event);
	}

	class ZFB_web_OnClick implements OnClickListener{

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.zfb_web_iv_back:
				CZ_ZhiFuBao_Web.this.finish();
				break;

			default:
				break;
			}
		}

	}

	public void user(String state){
		String tishi = "";
		if (state.equals("0")) {
			tishi = "支付失败！";
		}else {
			tishi = "支付成功！";
		}

		Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("提示");
		builder.setMessage(tishi);
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				CZ_ZhiFuBao_Web.this.finish();
			}
		});
		builder.create().show();
	}

}
